﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

public class ParsePhoneNumbers
{

    public static void ExtractNumbersBigFile(string inputFileName, string outputFileName)
    {
        string expression = @"\(\+(\d){3}\)\s(\d){3}\s(\d){3}-(\d){3}";
        using (StreamReader reader = new StreamReader(inputFileName))
        {
            using (StreamWriter writer = new StreamWriter(outputFileName))
            {
                StringBuilder builder = new StringBuilder(217);
                char[] buffer = new char[200];
                while (true)
                {
                    int charsRead = reader.Read(buffer, 0, buffer.Length);
                    if (charsRead == 0)
                    {
                        break;
                    }
                    builder.Append(buffer);                    
                    MatchCollection mCollection = Regex.Matches(builder.ToString(), expression);
                    foreach (var item in mCollection)
                    {
                        writer.WriteLine(item.ToString());
                    }
                    builder.Remove(0, 200);
                }
            }
        }
    }
}
